package com.xy.condition;


import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/7 15:16
 * @description 判断是否 linux 系统
 */


public class LinuxCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 1. 能获取IOC中的beanFactory
        context.getBeanFactory();

        //2. 获取类加载器
        context.getClassLoader();

        //3. 获取当前环境信息
        context.getEnvironment();

        //4. 获取bean定义的注册类
        context.getRegistry();

        String osName = context.getEnvironment().getProperty("os.name");
        return osName != null && osName.contains("Linux");
    }
}
